#include <string.h>
#include <string>
#include <iostream>
using namespace std;
//解析构造函数
//调用了析构函数，对象并不会被销毁
class Computer{
public:
    Computer(const char * brand, double price)
    : _brand(new char[strlen(brand) + 1]())
    , _price(price)
    {
        strcpy(_brand, brand);
    }
    ~Computer(){
        cout << "~Computer" << endl;
        if(_brand){
            delete [] _brand;   
             _brand = nullptr;
        }
    }
    void print(){
        cout << _brand << endl;
    }
private:
    char *_brand;
    double _price;

};

void test(){
    Computer pc("Xiaomi",5900);
    pc.print();
    //pc.~Computer();// 要是你主动调用这个会发送double free的问题
    //(前提是你没有手动设置——brand指针指向nullptr)
}

int main(int atgc, char * argv[])
{
    test();
    return 0;
}

